# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=ois
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
_base_ver=1.4.0
pkgver=1.4.0.124.564dd81
pkgrel=1
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgdesc="Object Oriented Input System (mingw-w64)"
arch=('any')
url="https://sourceforge.net/projects/wgois"
license=('custom:zlib/libpng')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('strip' '!libtool' 'staticlibs')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-gcc" "git")
source=("${_realname}"::"git+https://github.com/wgois/OIS.git"
        0001-install-pkg-config.patch
        0002-directx-linking.patch
        0003-InputManager-Cannot-have-pure-virtual-methods.patch)
sha256sums=('SKIP'
            '7979128918edac068ddb864300733a464420605b617f1003f040fd2985ffbce3'
            '274c2b4acd6474c708d9ad6783fa217ac93854bad91692777cdc518877d5a2de'
            '72f80ac5e0e4695598267517a5feee549df35aa2342b881a5fb9125974802e73')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "%s.%s.%s" "${_base_ver}" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd ${srcdir}/${_realname}
  patch -p1 -i "${srcdir}"/0001-install-pkg-config.patch
  patch -p1 -i "${srcdir}"/0002-directx-linking.patch
  patch -p1 -i "${srcdir}"/0003-InputManager-Cannot-have-pure-virtual-methods.patch
}

build() {
  local -a extra_config
  if check_option "debug" "y"; then
    extra_config+=( -DCMAKE_BUILD_TYPE=Debug )
  else
    extra_config+=( -DCMAKE_BUILD_TYPE=Release )
  fi

  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}
  
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DOIS_BUILD_SHARED_LIBS=ON \
    -DOIS_BUILD_DEMOS=ON \
    ${extra_config} \
    ../${_realname}

  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
}
